//
//  BSFooterView.m
//  BS
//
//  Created by lanou on 15/8/15.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "BSFooterView.h"
#import "UMSocial.h"

#import "BSComtentTableViewController.h"
@interface BSFooterView ()

@property (weak, nonatomic)UIButton *dingButton;

@property (weak, nonatomic)UIButton *caiButton;


@property (weak, nonatomic)UIButton *commentButton;


@end

@implementation BSFooterView

//自定义头试图
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self)
    {
        NSArray* objects = [[NSBundle mainBundle] loadNibNamed:@"BSFooterView"owner:self options:nil];
        UIView *nibView = [objects firstObject];
        _dingButton = (UIButton *)[nibView viewWithTag:1001];
        [_dingButton addTarget:self action:@selector(ding:) forControlEvents:UIControlEventTouchUpInside];
         _caiButton = (UIButton *)[nibView viewWithTag:1002];
        [_caiButton addTarget:self action:@selector(cai:) forControlEvents:UIControlEventTouchUpInside];
         _shareButton = (UIButton *)[nibView viewWithTag:1003];
        [_shareButton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
         _commentButton = (UIButton *)[nibView viewWithTag:1004];
        [_commentButton addTarget:self action:@selector(comment:) forControlEvents:UIControlEventTouchUpInside];
        UIView *contentView = self.contentView;
        CGSize contentViewSize = contentView.frame.size;
        nibView.frame = CGRectMake(0, 0, contentViewSize.width, contentViewSize.height);
        [contentView addSubview:nibView];
    }
    return self;
}


- (void)ding:(UIButton *)button{
    if (button.selected == YES) {
        button.selected = NO;
    }else{
        button.selected = YES;
    }
    NSLog(@"顶");
    //http://api.budejie.com/api/api_open.php?a=love&appname=baisishequ&asid=9A2EA4AE-2DEB-4479-A977-8CB5B3EFF60F&c=post&client=iphone&device=ios%20%E8%AE%BE%E5%A4%87&id=15284888&jbk=0&mac=&market=&openudid=f60e4fa5905641dfd3bec86efbf33da57105acc6&sex=m&tj_from=video&udid=&uid=15567628&ver=3.6.1
}


- (void)cai:(UIButton *)button{
    if (button.selected == YES) {
        button.selected = NO;
    }else{
        button.selected = YES;
    }
    NSLog(@"踩");
}


- (void)share:(UIButton *)button{
    NSLog(@"%@",_model.weixin_url);
    NSLog(@"image:%@",_model.image0);
    [UMSocialSnsService presentSnsIconSheetView:self.vc
                                         appKey:@"55d8471be0f55a97c2003361"
                                      shareText:self.model.text
                                     shareImage:[UIImage imageNamed:@"AppIcon29x29"]
                                shareToSnsNames:@[UMShareToQQ,UMShareToQzone,UMShareToSina,UMShareToWechatTimeline,UMShareToWechatSession]
                                       delegate:(id)self.vc];

    
    [UMSocialData defaultData].extConfig.qqData.url = self.model.weixin_url;
    [UMSocialData defaultData].extConfig.qzoneData.url = self.model.weixin_url;
    [UMSocialData defaultData].extConfig.wechatSessionData.url = self.model.weixin_url;
    [UMSocialData defaultData].extConfig.wechatTimelineData.url = self.model.weixin_url;
    [UMSocialData defaultData].extConfig.wechatSessionData.title = @"分享一条好玩的,点击查看";
    [UMSocialData defaultData].extConfig.wechatTimelineData.title = @"分享一条好玩的,点击查看";
    [UMSocialData defaultData].extConfig.qqData.title = @"分享一条好玩的段子,点击查看";
    [UMSocialData defaultData].extConfig.qzoneData.title = @"分享一条好玩的段子,点击查看";
//    [[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeImage url:self.model.image0];
//    [[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeMusic url:self.model.voiceuri];
//    [[UMSocialData defaultData].urlResource setResourceType:UMSocialUrlResourceTypeVideo url:self.model.videouri];
    
    
    NSLog(@"分享");

}



- (void)comment:(UIButton *)button{
    
    BSComtentTableViewController *commentVC = [[BSComtentTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
    commentVC.data_id = _model.ID;
    [self.nav pushViewController:commentVC animated:YES];
    
}


- (void)setModel:(BSListModel *)model{

    _model = model;
    if([_model.comment isEqualToString:@"0"]){

        _commentButton.userInteractionEnabled = NO;
    }
    else{
     _commentButton.userInteractionEnabled = YES;
    }
    [_dingButton setTitle:_model.ding forState:UIControlStateNormal];
      [_caiButton setTitle:_model.cai forState:UIControlStateNormal];
    [_commentButton setTitle:_model.comment forState:UIControlStateNormal];
    [_shareButton setTitle:_model.repost forState:UIControlStateNormal];
}
@end
